package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author ttao
 * @since 2023/4/23 11:28
 */

@Mapper
public interface SetmealMapper {
    /**
     * 根据分类查询套餐数量
     */
    @Select("select count(id) from setmeal where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 套餐管理分页条件查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> queryPage(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 添加套餐
     *
     * @param setmeal
     * @return
     */
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @AutoFill(OperationType.INSERT)
    @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) VALUES " +
            "(#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    int insert(Setmeal setmeal);

    /**
     * 根据id查询套餐信息
     *
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal selectById(Long id);

    /**
     * 批量删除套餐
     *
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 更新套餐
     *
     * @param setmeal
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    int updateById(Setmeal setmeal);

    /**
     * 根据分类id查询套餐
     *
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询包含的菜品列表
     *
     * @param setmeal
     * @return
     */
    List<DishItemVO> selectDishItemById(Setmeal setmeal);
}
